//初始化
mui.init();
var mask = mui.createMask(); //遮罩层
//获取本地储存数据
var my_phone = localStorage.getItem("my_phone");
var user_id = localStorage.getItem("user_id");
var is_realname, pay_password, description;
var status = 0; //修改手机号审核状态
//返回user页面
$(document).on('tap', '.my_order_back', function() {
	window.top.location.href = "../my/cash-center.html";
})

//提现明细
mui('body').on('tap', '.mui-control-item', function() {
	$(this).addClass("mui-active").siblings().removeClass('mui-active');
	var statusText = $(this).attr('data-status');
	userinfo(statusText)	
});


//提现明细接口调用
function userinfo(type) {
	if(type==1){
		mui.ajax(user_url + '/api/Balance/extractList', {
			dataType: 'json', //服务器返回json格式数据
			type: 'post', //HTTP请求类型
			timeout: 10000, //超时时间设置为10秒；
			success: function(data) {
				console.log(JSON.stringify(data))
				if(data.code == 10000) {
					var html = ""
					var listData = data.resp;
					for(var i = 0; i < listData.length; i++) {
						html += '<li class="mui-table-view-cell advance_record_li">'
						html += '<a class="mui-pull-left">'+listData[i].text+'（'+listData[i].status+'）<p>'+listData[i].create_time+'</p></a>'
						if(listData[i].sign==2){
							html += '<span class="mui-pull-right">-￥<i>'+listData[i].number+'</i></span>'
						}
						else{
							html += '<span class="mui-pull-right">+￥<i>'+listData[i].number+'</i></span>'
						}						
						html += '</li>';
					}
					$(".advance_record_list").html(html);
				}
				else{
					mui.alert(data.msg);
				}
			},
			error: function(xhr, type, errorThrown) { //异常处理；
				console.log(type);
			}
		});
	}
	else{
		mui.ajax(user_url + '/api/balance/balanceList', {
			dataType: 'json', //服务器返回json格式数据
			type: 'post', //HTTP请求类型
			timeout: 10000, //超时时间设置为10秒；
			success: function(data) {
				console.log(JSON.stringify(data))
				if(data.code == 10000) {
					var html = ""
					var listData = data.resp;
					for(var i = 0; i < listData.length; i++) {
						html += '<li class="mui-table-view-cell advance_record_li">'
						html += '<a class="mui-pull-left">'+listData[i].text+'<p>'+listData[i].create_time+'</p></a>'
						if(listData[i].sign==2){
							html += '<span class="mui-pull-right">-￥<i>'+listData[i].number+'</i></span>'
						}
						else{
							html += '<span class="mui-pull-right">+￥<i>'+listData[i].number+'</i></span>'
						}
						html += '</li>';
					}
					$(".advance_record_list").html(html);
				}
				else{
					mui.alert(data.msg);
				}
			},
			error: function(xhr, type, errorThrown) { //异常处理；
				console.log(type);
			}
		});
	}	
}

//页面进入执行方法
window.onload = function() {
	mui.plusReady(function() {
//		self = plus.webview.currentWebview();
		userinfo(1); //用户接口方法
		plus.nativeUI.closeWaiting(); //关闭等待
		mask.close(); //关闭遮罩层
		//页面刷新
		window.addEventListener('refresh_method', function(e) { //执行刷新
			location.reload();
		});
	});
}